package com.ellwood.copyright.common.core.result;

import com.ellwood.copyright.common.core.enums.HttpCodeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * @ProjectName: ell-copyright-pro
 * @PackageName: com.ellwood.copyright.common.core.result
 * @ClassName: EllResult
 * @Description: // TODO
 * @Author: Ellwood
 * @CreateDate: 2024/11/12 - 11:08
 * @Version: V1.0.0
 */
@Data
@Schema(description = "统一响应类")
public class EllResult<T>{

    @Schema(description = "响应码")
    private Integer CODE = HttpCodeEnum.SUCCESS.getCode();

    @Schema(description = "响应消息")
    private String MSG= HttpCodeEnum.SUCCESS.getMessage();

    @Schema(description = "响应数据")
    private T DATA;

    public static <T> EllResult<T> ok() {
        return ok(null);
    }

    public static <T> EllResult<T> ok(T data) {
        EllResult<T> result = new EllResult<>();
        result.setDATA(data);
        return result;
    }

    public static <T> EllResult<T> error() {
        return error(HttpCodeEnum.SYSTEM_ERROR);
    }

    public static <T> EllResult<T> error(String msg) {
        return error(HttpCodeEnum.SYSTEM_ERROR.getCode(), msg);
    }

    public static <T> EllResult<T> error(HttpCodeEnum httpCode) {
        return error(httpCode.getCode(), httpCode.getMessage());
    }

    public static <T> EllResult<T> error(int code, String msg) {
        EllResult<T> result = new EllResult<>();
        result.setCODE(code);
        result.setMSG(msg);
        return result;
    }

}
